package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ProductClassify;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.ProductClassifyQueryObject;
import cn.wolfcode.crm.service.IProductClassifyService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("productClassify")
public class ProductClassifyController {
    @Autowired
    private IProductClassifyService productClassifyService;

    @RequestMapping("")
    public String list(){
        return "productClassify/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(ProductClassifyQueryObject qo){
        return productClassifyService.query(qo);
    }


    @RequestMapping("queryBoot")
    @ResponseBody
    public List<ProductClassify> queryBoot(){
        return productClassifyService.queryBoot();
    }


    @RequestMapping("queryChildByParentId")
    @ResponseBody
    public List<ProductClassify> queryChildByParentId(Long parentId){
        return productClassifyService.queryChildByParentId(parentId);
    }


    @RequestMapping("delete")
    @ResponseBody
    public JsonResult list(Long id){
        JsonResult result = new JsonResult();
        try {
           productClassifyService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
           new JsonResult("删除操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(ProductClassify entity){
        JsonResult result = new JsonResult();
        try {
            productClassifyService.update(entity);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("更新操作失败");
        }
        return result;
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(ProductClassify entity){
        JsonResult result = new JsonResult();
        try {
            productClassifyService.insert(entity);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("保存操作失败");
        }
        return result;
    }
}
